<template>
  <view class="points-history-container">
    <text class="section-title">积分记录</text>
    
    <view class="history-list">
      <view class="history-item" v-for="record in pointsHistory" :key="record.id">
        <view class="history-icon">{{ record.icon }}</view>
        <view class="history-info">
          <text class="history-title">{{ record.title }}</text>
          <text class="history-time">{{ record.time }}</text>
        </view>
        <view class="history-points" :class="record.type">
          <text class="points-text">{{ record.type === 'earn' ? '+' : '-' }}{{ record.points }}</text>
        </view>
      </view>
      
      <!-- 空状态 -->
      <view class="empty-state" v-if="pointsHistory.length === 0">
        <text class="empty-icon">📝</text>
        <text class="empty-text">暂无积分记录</text>
        <text class="empty-desc">开始使用功能来获得积分吧</text>
      </view>
    </view>
  </view>
</template>

<script>
import pointsManager from '@/utils/points-manager.js'

export default {
  name: 'PointsHistory',
  data() {
    return {
      pointsHistory: []
    }
  },
  
  mounted() {
    this.loadPointsHistory()
  },
  
  onShow() {
    this.loadPointsHistory()
  },
  
  methods: {
    loadPointsHistory() {
      this.pointsHistory = pointsManager.getRecentActivities()
    },
    
    // 刷新历史记录
    refresh() {
      this.loadPointsHistory()
    }
  }
}
</script>

<style scoped>
.points-history-container {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 30rpx;
  display: block;
}

.history-list {
  max-height: 600rpx;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #f0f0f0;
}

.history-item:last-child {
  border-bottom: none;
}

.history-icon {
  font-size: 32rpx;
  margin-right: 20rpx;
}

.history-info {
  flex: 1;
}

.history-title {
  font-size: 26rpx;
  color: #333;
  display: block;
  margin-bottom: 5rpx;
}

.history-time {
  font-size: 22rpx;
  color: #999;
}

.history-points {
  text-align: right;
}

.history-points.earn .points-text {
  color: #4caf50;
}

.history-points.spend .points-text {
  color: #ff4757;
}

.points-text {
  font-size: 26rpx;
  font-weight: bold;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 60rpx 20rpx;
  color: #999;
}

.empty-icon {
  font-size: 80rpx;
  display: block;
  margin-bottom: 20rpx;
}

.empty-text {
  font-size: 28rpx;
  font-weight: bold;
  display: block;
  margin-bottom: 10rpx;
}

.empty-desc {
  font-size: 24rpx;
  opacity: 0.8;
}
</style>
